FROM centos:7

COPY temp /home/temp
COPY aliyun-mirror.repo /etc/yum.repos.d/CentOS-Base.repo
COPY aliyun-epel.repo /etc/yum.repos.d/epel.repo
WORKDIR /home/temp

RUN useradd -r -s /sbin/nologin -d /home/wwwroot -m -k no www \
	&& mkdir -p /home/wwwroot/www/frontend/web \
	&& mkdir -p /home/wwwroot/www/backend/web \
	&& cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \

#Install gcc make
	&& yum install -y gcc \
	gcc-c++ \
	make \
	autoconf \
	supervisor \
	ntpd \

#Install PHP library
	epel-release \
	zlib-devel \
	openssl-devel \
	pcre-devel \
	libxml2-devel \
	libcurl-devel \
	libxslt-devel \
	libpng-devel \
	libjpeg-devel \
	libmcrypt-devel \
	libicu-devel \
	freetype-devel \
	gmp-devel \
    sqlite-devel \
	oniguruma \
	oniguruma-devel \

	&& cd /home/temp/ \
	&& tar zxf nginx-1.18.0.tar.gz && tar zxf php-7.4.16.tar.gz && tar zxf mongodb-1.2.11.tgz && tar zxf xdebug-3.0.3.tgz && tar zxf rabbitmq-c-0.8.0.tar.gz && tar zxf amqp-1.9.4.tgz && tar zxf icu4c-52_1-src.tgz \

#Make install libzip for php7.3 error: system libzip must be upgraded to version >= 0.11 and configure报错error: off_t undefined; check your library configuration
#	&& cd /home/temp/libzip-1.3.2 \
#	&& ./configure \
#	&& make && make install \
#	&& echo -e "/usr/local/lib64\n/usr/local/lib\n/usr/lib\n/usr/lib64">>/etc/ld.so.conf \
#	&& ldconfig -v \

#Make install nginx
	&& cd /home/temp/nginx-1.18.0 \
	&& ./configure --prefix=/usr/local/nginx \
	--user=www --group=www \
	--error-log-path=/home/wwwlogs/error.log \
	--http-log-path=/home/wwwlogs/access.log \
	--pid-path=/usr/local/nginx/logs/nginx.pid \
	--with-pcre \
	--with-http_ssl_module \
	--without-mail_pop3_module \
	--without-mail_imap_module \
	--with-http_gzip_static_module \
	&& make \
	&& make install \


#Make install php
	&& cd /home/temp/php-7.4.16 \
	&& ./configure --prefix=/usr/local/php \
	--with-config-file-path=/usr/local/php/etc \
	--with-config-file-scan-dir=/usr/local/php/etc/php.d \
	--with-fpm-user=www \
	--with-fpm-group=www \
	--with-mcrypt=/usr/include \
	--with-mysqli=mysqlnd \
	--with-pdo-mysql=mysqlnd \
	--with-mysql-sock=/tmp/mysql.sock \
	--enable-mysqlnd \
	--with-openssl \
	--enable-gd \
	--with-iconv \
	--with-zlib \
	--with-gettext \
	--with-curl \
	--with-png-dir \
	--with-jpeg-dir \
	--with-freetype \
	--with-xmlrpc \
	--with-mhash \
	--with-pear \
	--with-gmp \
	--enable-fpm \
	--enable-xml \
	--enable-shmop \
	--enable-sysvsem \
	--enable-inline-optimization \
	--enable-mbregex \
	--enable-mbstring \
	--enable-ftp \
	--enable-gd-native-ttf \
	--enable-mysqlnd \
	--enable-pcntl \
	--enable-sockets \
	--enable-soap \
	--enable-session \
	--enable-opcache \
	--enable-bcmath \
	--enable-exif \
	--enable-fileinfo \
	--disable-rpath \
	--enable-ipv6 \
	--disable-debug \
	&& make \
	&& make install \
	&& ln -s /usr/local/php/bin/php /usr/bin/php \
	&& ln -s /usr/local/php/bin/phpize /usr/bin/phpize \
	&& ln -s /usr/local/php/bin/php-config /usr/bin/php-config \
	&& ln -s /usr/local/php/bin/pecl /usr/bin/pecl \

#PHP extensions:intl
        && mkdir /usr/local/icu \
        && cd /home/temp/icu/source \
        && ./configure --prefix=/usr/local/icu \
        && make \
        && make install \

# Make install intl
	&& cd /home/temp/php-7.4.16/ext/intl \
	&& phpize \
	&& ./configure --enable-intl --with-icu-dir=/usr/local/icu/ --with-php-config=/usr/local/php/bin/php-config \
	&& make \
	&& cp /home/temp/php-7.4.16/ext/intl/modules/intl.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ \


#Make install mongod_extension
	&& cd /home/temp/mongodb-1.2.11 \
	&& phpize && ./configure \
	&& make install \

#Make install xdebug
	&& cd /home/temp/xdebug-3.0.3 \
	&& phpize && ./configure --enable-xdebug \
	&& make \
	&& make install \

#Make install amqp
	&& cd /home/temp/rabbitmq-c-0.8.0 \
	&& ./configure --prefix=/usr/local/rabbitmq-c-0.8.0 \
	&& make && make install \

	&& cd /home/temp/amqp-1.9.4 \
	&& phpize \
	&& ./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.8.0 \
	&& make && make install \

#Make install composer
	&& php -r "readfile('https://getcomposer.org/installer');" | php \
	&& mv composer.phar /usr/local/bin/composer \

	&& yum remove -y gcc \
	gcc-c++ \
	make \
	autoconf \
	libtool \
	&& yum clean all \
	&& rm -rf /tmp/* /var/cache/yum /etc/my.cnf{,.d} \
	&& mkdir -p --mode=0755 /var/cache/yum \
	&& find /var/log -type f -delete \
	&& rm -rf /home/temp/*

COPY conf/supervisord.conf /etc/supervisord.conf
COPY conf/php-fpm.conf /usr/local/php/etc/php-fpm.conf
COPY conf/php.ini /usr/local/php/etc/php.ini
COPY conf/index.php /home/wwwroot/www/frontend/web/index.php
COPY conf/nginx.conf /usr/local/nginx/conf/nginx.conf
COPY conf/php-fpm /etc/init.d/php-fpm

RUN chmod u+x /etc/init.d/php-fpm \
	&& chown -R www:www /home/wwwroot \
	&& cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

EXPOSE 80

ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
